package graphics.datastructures.hierarchalbb;

import graphics.datastructures.BoundingBox;
import graphics.raytracing.CastResult;
import graphics.raytracing.Ray;
import graphics.raytracing.Tracable;

class DualBox<T extends Tracable<? extends Tracable<?>>> implements Box<T> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7894113203781913438L;
	private Box<T> _one;
	private Box<T> _two;
	private BoundingBox<T> _box;
	public DualBox(Box<T> one, Box<T> two,BoundingBox<T> box) {
		_one = one;
		_two = two;
		_box = box;
	}

	@Override
	public CastResult<T> cast(Ray ray) {
		CastResult<T> one=null;
		CastResult<T> two=null;
		if(_one.getBoundingBox().intersects(ray))
			one = _one.cast(ray);
		if(_two.getBoundingBox().intersects(ray))
			two = _two.cast(ray);
		if(one==null)
			return two;
		if(two==null)
			return one;
		if(one.distance()<two.distance())
			return one;
		else
			return two;
	}

	@Override
	public float[][] getBB() {
		return null;
	}

	@Override
	public BoundingBox<T> getBoundingBox() {
		return _box;
	}
}
